package com.lagou.filter;

import com.lagou.common.FilterConstant;
import com.lagou.common.InvokerContext;
import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.rpc.*;

@Activate(group = {CommonConstants.CONSUMER})
public class TransportIPFilter implements Filter {

    public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
        Object ip = InvokerContext.getValue(FilterConstant.VISIT_IP_KEY);
        RpcContext.getContext().setAttachment(FilterConstant.VISIT_IP_KEY, String.valueOf(ip));
        try {
            return invoker.invoke(invocation);
        } finally {
            RpcContext.removeContext();
        }
    }
}
